package com.jtjrenren.android.taxi.driver.core.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jtjrenren.android.taxi.driver.base.BaseRcyAdapter;
import com.jtjrenren.android.taxi.driver.R;
import com.jtjrenren.android.taxi.driver.bean.api.ApiYYD;
import com.library.utils.DateUtils;

/**
 * Created by Administrator on 2016/5/10.
 */
public class YydAdapter extends BaseRcyAdapter<ApiYYD> {
    public interface ItemClick {
        void onItemClick(ApiYYD order);
    }

    public YydAdapter(Context context) {
        super(context);
    }

    private ItemClick listener;

    public void setListener(ItemClick listener) {
        this.listener = listener;
    }

    @Override
    public RecyclerView.ViewHolder getItemViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_yydlist, parent, false);
        return new YydViewHolder(view);
    }

    @Override
    public void onBindItemViewHolder(RecyclerView.ViewHolder holder, int position) {
        YydViewHolder yydViewHolder = (YydViewHolder) holder;

        ApiYYD order = list.get(position);
        String date = DateUtils.friendly_time3(order.getBookingTime());

        yydViewHolder.tv_time.setText(date);
        yydViewHolder.tv_start.setText(order.getStartAddr());
        yydViewHolder.tv_end.setText(order.getEndAddr());
    }

    public class YydViewHolder extends RecyclerView.ViewHolder {
        private TextView tv_time, tv_start, tv_end;

        public YydViewHolder(View itemView) {
            super(itemView);

            tv_time = (TextView) itemView.findViewById(R.id.yydlist_time);
            tv_start = (TextView) itemView.findViewById(R.id.yydlist_start);
            tv_end = (TextView) itemView.findViewById(R.id.yydlist_end);

            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (listener != null)
                        listener.onItemClick(list.get(getAdapterPosition()));
                }
            });
        }
    }
}
